/*
 * Copyright (c) 2009 by Vsevolod Velichko <torkvemada@nigma.ru>
 *
 ***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 3 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************
*/

#include "indigo.h"
zend_module_entry indigo_module_entry =
{
#if ZEND_MODULE_API_NO >= 20010901
	STANDARD_MODULE_HEADER,
#endif /* ZEND_MODULE_API_NO >= 20010901 */
	PHP_INDIGO_EXTNAME,
	NULL, /* Functions */
	PHP_MINIT(indigo), /* MINIT */
	PHP_MSHUTDOWN(indigo), /* MSHUTDOWN */
	NULL, /* RINIT */
	NULL, /* RSHUTDOWN */
	PHP_MINFO(indigo), /* MINFO */
#if ZEND_MODULE_API_NO >= 20010901
	PHP_INDIGO_VERSION,
#endif /* ZEND_MODULE_API_NO >= 20010901 */
	STANDARD_MODULE_PROPERTIES
};

#ifdef COMPILE_DL_INDIGO
#ifdef __cplusplus
extern "C"
{
#endif
	/* Signal to PHP that Indigo must be compiled as an extension */
	ZEND_GET_MODULE(indigo)
#ifdef __cplusplus
}
#endif
#endif /* COMPILE_DL_INDIGO */

#ifdef HAVE_DINGO
zend_class_entry *dingo_class_entry;

static function_entry dingo_class_functions[] =
{
	PHP_ME(PHP_DINGO_CLASS_NAME, __construct, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
	PHP_ME(PHP_DINGO_CLASS_NAME, __destruct, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
	PHP_ME(PHP_DINGO_CLASS_NAME, __toString, NULL, ZEND_ACC_PUBLIC)
	PHP_ME(PHP_DINGO_CLASS_NAME, reset, NULL, ZEND_ACC_PUBLIC)
	PHP_ME(PHP_DINGO_CLASS_NAME, setLogPath, NULL, ZEND_ACC_PUBLIC)
	PHP_ME(PHP_DINGO_CLASS_NAME, setLoadHighlighting, NULL, ZEND_ACC_PUBLIC)
	PHP_ME(PHP_DINGO_CLASS_NAME, setInputFormat, NULL, ZEND_ACC_PUBLIC)
	PHP_ME(PHP_DINGO_CLASS_NAME, loadMolFromFile, NULL, ZEND_ACC_PUBLIC)
	PHP_ME(PHP_DINGO_CLASS_NAME, loadMolFromString, NULL, ZEND_ACC_PUBLIC)
	PHP_ME(PHP_DINGO_CLASS_NAME, loadReactionFromFile, NULL, ZEND_ACC_PUBLIC)
	PHP_ME(PHP_DINGO_CLASS_NAME, loadReactionFromString, NULL, ZEND_ACC_PUBLIC)
	PHP_ME(PHP_DINGO_CLASS_NAME, setOutputFormat, NULL, ZEND_ACC_PUBLIC)
	PHP_ME(PHP_DINGO_CLASS_NAME, setOutputFile, NULL, ZEND_ACC_PUBLIC)
	PHP_ME(PHP_DINGO_CLASS_NAME, setImageSize, NULL, ZEND_ACC_PUBLIC)
	PHP_ME(PHP_DINGO_CLASS_NAME, setBondLength, NULL, ZEND_ACC_PUBLIC)
	PHP_ME(PHP_DINGO_CLASS_NAME, setMarginFactor, NULL, ZEND_ACC_PUBLIC)
	PHP_ME(PHP_DINGO_CLASS_NAME, setRelativeThickness, NULL, ZEND_ACC_PUBLIC)
	PHP_ME(PHP_DINGO_CLASS_NAME, setBaseColor, NULL, ZEND_ACC_PUBLIC)
	PHP_ME(PHP_DINGO_CLASS_NAME, setBackgroundColor, NULL, ZEND_ACC_PUBLIC)
	PHP_ME(PHP_DINGO_CLASS_NAME, setImplicitHydrogenMode, NULL, ZEND_ACC_PUBLIC)
	PHP_ME(PHP_DINGO_CLASS_NAME, setColoring, NULL, ZEND_ACC_PUBLIC)
	PHP_ME(PHP_DINGO_CLASS_NAME, setValencesVisible, NULL, ZEND_ACC_PUBLIC)
	PHP_ME(PHP_DINGO_CLASS_NAME, setAtomIdsVisible, NULL, ZEND_ACC_PUBLIC)
	PHP_ME(PHP_DINGO_CLASS_NAME, setBondIdsVisible, NULL, ZEND_ACC_PUBLIC)
	PHP_ME(PHP_DINGO_CLASS_NAME, setStereoOldStyle, NULL, ZEND_ACC_PUBLIC)
	PHP_ME(PHP_DINGO_CLASS_NAME, setLabelMode, NULL, ZEND_ACC_PUBLIC)
	PHP_ME(PHP_DINGO_CLASS_NAME, setAromatization, NULL, ZEND_ACC_PUBLIC)
	PHP_ME(PHP_DINGO_CLASS_NAME, setHighlightThicknessEnabled, NULL, ZEND_ACC_PUBLIC)
	PHP_ME(PHP_DINGO_CLASS_NAME, setHighlightColor, NULL, ZEND_ACC_PUBLIC)
	PHP_ME(PHP_DINGO_CLASS_NAME, setAAMColor, NULL, ZEND_ACC_PUBLIC)
	PHP_ME(PHP_DINGO_CLASS_NAME, setCenterDoubleBondWhenStereoAdjacent, NULL, ZEND_ACC_PUBLIC)
	PHP_ME(PHP_DINGO_CLASS_NAME, render, NULL, ZEND_ACC_PUBLIC)
	PHP_ME(PHP_DINGO_CLASS_NAME, getRenderedString, NULL, ZEND_ACC_PUBLIC)
	{NULL, NULL, NULL}
};
#endif /* HAVE_DINGO */

#ifdef HAVE_CANO
zend_class_entry *cano_class_entry;

static function_entry cano_class_functions[] =
{
	PHP_ME(PHP_CANO_CLASS_NAME, getVersion, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
	PHP_ME(PHP_CANO_CLASS_NAME, getCanonicalSmiles, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
	PHP_ME(PHP_CANO_CLASS_NAME, getInChI, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
	{NULL, NULL, NULL}
};
#endif /* HAVE_CANO */

/* Module init */
PHP_MINIT_FUNCTION(indigo)
{
#ifdef HAVE_DINGO
	/* Register class Dingo */
	zend_class_entry dingo_ce;
	INIT_CLASS_ENTRY(dingo_ce, PHP_DINGO_CLASS_NAME, dingo_class_functions);
	dingo_class_entry = zend_register_internal_class(&dingo_ce TSRMLS_CC);
	/* Register Dingo ID property */
	zend_declare_property_long(dingo_class_entry, (char*)"ID", 2, -1, ZEND_ACC_PRIVATE TSRMLS_CC);
#endif /* HAVE_DINGO */

#ifdef HAVE_CANO
	/* Register class Cano */
	zend_class_entry cano_ce;
	INIT_CLASS_ENTRY(cano_ce, PHP_CANO_CLASS_NAME, cano_class_functions);
	cano_class_entry = zend_register_internal_class(&cano_ce TSRMLS_CC);
#endif /* HAVE_CANO */

	return SUCCESS;
}
/* Module shutdown */
PHP_MSHUTDOWN_FUNCTION(indigo)
{
	return SUCCESS;
}
/* Module info for phpinfo() */
PHP_MINFO_FUNCTION(indigo)
{
	php_info_print_table_start();
	php_info_print_table_colspan_header(2, (char*)"Indigo libraries");
	php_info_print_table_row(2, "PHP-Indigo version", PHP_INDIGO_VERSION);
#ifdef HAVE_DINGO
	php_info_print_table_row(2, "Dingo support", "enabled");
	php_info_print_table_row(2, "Dingo version", dingoVersionRevisionString() );
#else /* HAVE_DINGO */
	php_info_print_table_row(2, "Dingo support", "disabled");
#endif /* HAVE_DINGO */
#ifdef HAVE_CANO
	php_info_print_table_row(2, "Cano support", "enabled");
	php_info_print_table_row(2, "Cano version", canoGetVersion());
#else /* HAVE_CANO */
	php_info_print_table_row(2, "Cano support", "disabled");
#endif /* HAVE_CANO */
	php_info_print_table_end();
}


